package parameter.crop;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import dao.MyDAO;
import parameter.Calendar1;
import util.TipsTextField;

public class ActuTraCrop3 extends JFrame{
	private static JTextField textField_0; // 萎焉点基质势值
	private static JTextField textField_1;// 种植日期年值
	private static JTextField textField_2;// 最适土壤水基质势上限值
	private static JTextField textField_3;// 最适土壤水基质势下限值
	private static JTextField textField_4;// 土壤水分胁迫函数形参值
	private static JTextField textField_5;// 最大扎根深度a值
	//static JComboBox comboBox = new JComboBox();// 作物种类值选择
	private static JTextField textField_6;// 最大扎根深度b值
	private static JTextField textField_7;// 最大扎根深度c值
	static int flag = 0;// flag=0证明数据库有这个作物，不用插入
	static Crop crop = new Crop();
	static SoilWxp soilWxp = new SoilWxp();
	static Cropkind cropkind =new Cropkind();
	private static JTextField textField;// 土壤水渗透上限值
	private static JTextField textField_10;// 土壤水渗透下限值
	private static JTextField textField_11;// //土壤盐分胁迫函数形参X值
	private static JTextField textField_12;// 相对根长密度分布参数S值

	public ActuTraCrop3() throws Exception {
		// TODO Auto-generated constructor stub
		JFrame frame = new JFrame();
		frame.setTitle("作物参数");
		frame.getContentPane().setFont(new Font("宋体", Font.PLAIN, 12));
		frame.getContentPane().setEnabled(false);
		frame.getContentPane().setBackground(SystemColor.text);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] {0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		frame.getContentPane().setLayout(gridBagLayout);
        frame.setSize(700, 600);
		// 题目标签
		JLabel label = new JLabel(
				"实际蒸腾估算根区算术平均法土壤水盐传感器");
		label.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridx = 1;
		gbc_label.gridy = 0;
		frame.getContentPane().add(label, gbc_label);

		
		// 控制区标签1
		JLabel label_2 = new JLabel("\u5F53\u524D\u63A7\u5236\u533A:");
		GridBagConstraints gbc_label_2 = new GridBagConstraints();
		gbc_label_2.insets = new Insets(0, 0, 5, 5);
		gbc_label_2.gridx = 3;
		gbc_label_2.gridy = 1;
		frame.getContentPane().add(label_2, gbc_label_2);
		// 控制区标签2
		String sql0 = "select name from ctrlzone_para ;";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		conn = MyDAO.getConnection();

		stmt = conn.createStatement();

		rs = stmt.executeQuery(sql0);
		if (rs.next()) {
			crop.setCtrlzone_name(rs.getString(1));
			JLabel label_3 = new JLabel(rs.getString(1));
			GridBagConstraints gbc_label_3 = new GridBagConstraints();
			gbc_label_3.insets = new Insets(0, 0, 5, 5);
			gbc_label_3.gridx = 4;
			gbc_label_3.gridy = 1;
			frame.getContentPane().add(label_3, gbc_label_3);
		}

		// 提示语标签
		JLabel label_4 = new JLabel(
				"\u8BF7\u6B63\u786E\u8F93\u5165\u4EE5\u4E0B\u53C2\u6570\uFF1A");
		label_4.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_label_4 = new GridBagConstraints();
		gbc_label_4.anchor = GridBagConstraints.EAST;
		gbc_label_4.insets = new Insets(0, 0, 5, 5);
		gbc_label_4.gridx = 0;
		gbc_label_4.gridy = 2;
		frame.getContentPane().add(label_4, gbc_label_4);
		final ArrayList crop_kind = cropkind.getCrop_kind();
		final DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel();
		for (int i = 0; i < crop_kind.size(); i++) {
			if (i == 0 || crop_kind.get(i) != null) {
				defaultComboBoxModel.addElement(crop_kind.get(i));
			}
		}
				
						// 作物种类标签
						JLabel label_7 = new JLabel("\u4F5C\u7269\u79CD\u7C7B\uFF1A");
						label_7.setFont(new Font("宋体", Font.PLAIN, 12));
						GridBagConstraints gbc_label_7 = new GridBagConstraints();
						gbc_label_7.anchor = GridBagConstraints.WEST;
						gbc_label_7.insets = new Insets(0, 0, 5, 5);
						gbc_label_7.gridx = 0;
						gbc_label_7.gridy = 3;
						frame.getContentPane().add(label_7, gbc_label_7);
						frame.getContentPane().add(label_7, gbc_label_7);
				JComboBox comboBox = new JComboBox();// 作物种类值选择
				comboBox.setBackground(SystemColor.text);
				comboBox.setFont(new Font("宋体", Font.PLAIN, 12));
				
						// 作物种类值选择
				
						comboBox.setEditable(true);
						comboBox.setModel(defaultComboBoxModel);
						GridBagConstraints gbc_comboBox = new GridBagConstraints();
						gbc_comboBox.anchor = GridBagConstraints.WEST;
						gbc_comboBox.insets = new Insets(0, 0, 5, 5);
						gbc_comboBox.gridx = 1;
						gbc_comboBox.gridy = 3;
						frame.getContentPane().add(comboBox, gbc_comboBox);
				// crop.setName((String) defaultComboBoxModel.getSelectedItem());

				// 萎焉点基质势标签
				JLabel lblhwcm = new JLabel(
						"\u840E\u7109\u70B9\u57FA\u8D28\u52BFhw:");
				lblhwcm.setFont(new Font("宋体", Font.PLAIN, 12));
				GridBagConstraints gbc_lblhwcm = new GridBagConstraints();
				gbc_lblhwcm.anchor = GridBagConstraints.WEST;
				gbc_lblhwcm.insets = new Insets(0, 0, 5, 5);
				gbc_lblhwcm.gridx = 3;
				gbc_lblhwcm.gridy = 3;
				frame.getContentPane().add(lblhwcm, gbc_lblhwcm);
		
				// 萎焉点基质势值
				textField_0 = new TipsTextField("cm");
				textField_0.setFont(new Font("宋体", Font.PLAIN, 12));
				GridBagConstraints gbc_textField = new GridBagConstraints();
				gbc_textField.anchor = GridBagConstraints.WEST;
				gbc_textField.insets = new Insets(0, 0, 5, 0);
				gbc_textField.gridx = 5;
				gbc_textField.gridy = 3;
				frame.getContentPane().add(textField_0, gbc_textField);
				textField_0.setColumns(10);
				//textField_0.setToolTipText("cm");
		// crop.setWilt_jzs(textField_0.getText());

		// 种植日期标签
		JLabel label_5 = new JLabel(
				"\u79CD\u690D\u65E5\u671F\uFF08*\u5E74*\u6708*\u65E5\uFF09");
		GridBagConstraints gbc_label_5 = new GridBagConstraints();
		gbc_label_5.anchor = GridBagConstraints.WEST;
		gbc_label_5.insets = new Insets(0, 0, 5, 5);
		gbc_label_5.gridx = 0;
		gbc_label_5.gridy = 4;
		frame.getContentPane().add(label_5, gbc_label_5);
		
		// 种植日期
		// 种植日期时间值
		textField_1 = new JTextField();
		 Calendar cal = Calendar.getInstance();
	        //textField_1 .setText(cal.get(Calendar.YEAR)+"-0"+(cal.get(Calendar.MONTH)+1)+"-"+cal.get(Calendar.DATE));
	        textField_1.setFont(new Font("宋体", Font.PLAIN, 12));
			textField_1.setBackground(Color.WHITE);
			final GridBagConstraints gbc_textField_1 = new GridBagConstraints();
			gbc_textField_1.anchor = GridBagConstraints.WEST;
			gbc_textField_1.insets = new Insets(0, 0, 5, 5);
			gbc_textField_1.gridx = 1;
			gbc_textField_1.gridy = 4;
			//frame.getContentPane().add(textField_1, gbc_textField_1);
			textField_1.setColumns(10);
			 Calendar1 ser = Calendar1.getInstance();
			 ser.register(textField_1);
			 frame.getContentPane().add(textField_1, gbc_textField_1);
		
		// 最适土壤水基质势上限标签1
		JLabel label_6 = new JLabel(
				"\u6700\u9002\u4F5C\u7269\u751F\u957F\u571F\u58E4");
		label_6.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_label_6 = new GridBagConstraints();
		gbc_label_6.anchor = GridBagConstraints.WEST;
		gbc_label_6.insets = new Insets(0, 0, 5, 5);
		gbc_label_6.gridx = 0;
		gbc_label_6.gridy = 5;
		frame.getContentPane().add(label_6, gbc_label_6);

		// 最适土壤水基质势上限标签2
		JLabel lblhhcm = new JLabel(
				"\u6C34\u57FA\u8D28\u52BF\u4E0A\u9650hH:(cm)");
		lblhhcm.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lblhhcm = new GridBagConstraints();
		gbc_lblhhcm.anchor = GridBagConstraints.WEST;
		gbc_lblhhcm.insets = new Insets(0, 0, 5, 5);
		gbc_lblhhcm.gridx = 0;
		gbc_lblhhcm.gridy = 6;
		frame.getContentPane().add(lblhhcm, gbc_lblhhcm);
		
				// 最适土壤水基质势上限值
				textField_2 = new TipsTextField("cm");
				textField_2.setFont(new Font("宋体", Font.PLAIN, 12));
				GridBagConstraints gbc_textField_2 = new GridBagConstraints();
				gbc_textField_2.anchor = GridBagConstraints.WEST;
				gbc_textField_2.insets = new Insets(0, 0, 5, 5);
				gbc_textField_2.gridx = 1;
				gbc_textField_2.gridy = 6;
				frame.getContentPane().add(textField_2, gbc_textField_2);
				textField_2.setColumns(10);
				//textField_2.setToolTipText("cm");
		// crop.setSoilWjzs_up(textField_2.getText());

		// 最大扎根深度总标签
		JLabel lbllr = new JLabel("\u6700\u5927\u624E\u6839\u6DF1\u5EA6Lr:");
		lbllr.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lbllr = new GridBagConstraints();
		gbc_lbllr.insets = new Insets(0, 0, 5, 5);
		gbc_lbllr.gridx = 3;
		gbc_lbllr.gridy = 6;
		frame.getContentPane().add(lbllr, gbc_lbllr);

		// 最大扎根深度a标签
		JLabel lblA = new JLabel("a");
		GridBagConstraints gbc_lblA = new GridBagConstraints();
		gbc_lblA.insets = new Insets(0, 0, 5, 5);
		gbc_lblA.gridx = 4;
		gbc_lblA.gridy = 6;
		frame.getContentPane().add(lblA, gbc_lblA);

		// 最大扎根深度a值
		textField_5 = new TipsTextField("cm");
		textField_5.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_textField_5 = new GridBagConstraints();
		gbc_textField_5.anchor = GridBagConstraints.WEST;
		gbc_textField_5.insets = new Insets(0, 0, 5, 0);
		gbc_textField_5.gridx = 5;
		gbc_textField_5.gridy = 6;
		frame.getContentPane().add(textField_5, gbc_textField_5);
		textField_5.setColumns(10);
		//textField_5.setToolTipText("cm");

		// 最大扎根深度b标签
		JLabel lblSdfdffgd = new JLabel("b");
		GridBagConstraints gbc_lblSdfdffgd = new GridBagConstraints();
		gbc_lblSdfdffgd.anchor = GridBagConstraints.EAST;
		gbc_lblSdfdffgd.insets = new Insets(0, 0, 5, 5);
		gbc_lblSdfdffgd.gridx = 4;
		gbc_lblSdfdffgd.gridy = 7;
		frame.getContentPane().add(lblSdfdffgd, gbc_lblSdfdffgd);

		// 最大扎根深度b值
		textField_6 = new TipsTextField("cm");
		textField_6.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_textField_6 = new GridBagConstraints();
		gbc_textField_6.anchor = GridBagConstraints.WEST;
		gbc_textField_6.insets = new Insets(0, 0, 5, 0);
		gbc_textField_6.gridx = 5;
		gbc_textField_6.gridy = 7;
		frame.getContentPane().add(textField_6, gbc_textField_6);
		textField_6.setColumns(10);
		//textField_6.setToolTipText("cm");

		// 最适土壤水基质势下限标签1
		JLabel label_3 = new JLabel(
				"\u6700\u9002\u4F5C\u7269\u751F\u957F\u571F\u58E4");
		label_3.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_label_3 = new GridBagConstraints();
		gbc_label_3.anchor = GridBagConstraints.WEST;
		gbc_label_3.insets = new Insets(0, 0, 5, 5);
		gbc_label_3.gridx = 0;
		gbc_label_3.gridy = 8;
		frame.getContentPane().add(label_3, gbc_label_3);

		// 最大扎根深度c值
		textField_7 = new TipsTextField("cm");
		textField_7.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_textField_7 = new GridBagConstraints();
		gbc_textField_7.anchor = GridBagConstraints.WEST;
		gbc_textField_7.insets = new Insets(0, 0, 5, 0);
		gbc_textField_7.gridx = 5;
		gbc_textField_7.gridy = 8;
		frame.getContentPane().add(textField_7, gbc_textField_7);
		textField_7.setColumns(10);
		//textField_7.setToolTipText("cm");

		// 最适土壤水基质势下限标签2
		JLabel lblhhcm_1 = new JLabel(
				"\u6C34\u57FA\u8D28\u52BF\u4E0B\u9650hH:(cm)");
		lblhhcm_1.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lblhhcm_1 = new GridBagConstraints();
		gbc_lblhhcm_1.anchor = GridBagConstraints.WEST;
		gbc_lblhhcm_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblhhcm_1.gridx = 0;
		gbc_lblhhcm_1.gridy = 9;
		frame.getContentPane().add(lblhhcm_1, gbc_lblhhcm_1);
		// crop.setSoilWjzs_low(textField_3.getText());
		// 最大扎根深度c标签
		JLabel lblC = new JLabel("c");
		GridBagConstraints gbc_lblC = new GridBagConstraints();
		gbc_lblC.insets = new Insets(0, 0, 5, 5);
		gbc_lblC.gridx = 4;
		gbc_lblC.gridy = 8;
		frame.getContentPane().add(lblC, gbc_lblC);
		
				// 最适土壤水基质势下限值
				textField_3 = new TipsTextField("cm");
				textField_3.setFont(new Font("宋体", Font.PLAIN, 12));
				textField_3.setColumns(10);
				GridBagConstraints gbc_textField_3 = new GridBagConstraints();
				gbc_textField_3.anchor = GridBagConstraints.WEST;
				gbc_textField_3.insets = new Insets(0, 0, 5, 5);
				gbc_textField_3.gridx = 1;
				gbc_textField_3.gridy = 9;
				frame.getContentPane().add(textField_3, gbc_textField_3);
				//textField_3.setToolTipText("cm");

		// 土壤水分胁迫函数形参标签
		JLabel lblNewLabel = new JLabel(
				"\u571F\u58E4\u6C34\u5206\u80C1\u8FEB\u51FD\u6570\u5F62\u53C2Y\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 0;
		gbc_lblNewLabel.gridy = 10;
		frame.getContentPane().add(lblNewLabel, gbc_lblNewLabel);
		
				// 土壤水分胁迫函数形参值
				textField_4 = new TipsTextField("输入文本");
				textField_4.setFont(new Font("宋体", Font.PLAIN, 12));
				GridBagConstraints gbc_textField_4 = new GridBagConstraints();
				gbc_textField_4.anchor = GridBagConstraints.WEST;
				gbc_textField_4.insets = new Insets(0, 0, 5, 5);
				gbc_textField_4.gridx = 1;
				gbc_textField_4.gridy = 10;
				frame.getContentPane().add(textField_4, gbc_textField_4);
				textField_4.setColumns(10);
				//textField_4.setToolTipText("输入文本");
		// 土壤水渗透上限标签
		JLabel lblcm = new JLabel(
				"\u571F\u58E4\u6C34\u5206\u6E17\u900F\u4E0A\u9650\uFF1A(cm)");
		lblcm.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lblcm = new GridBagConstraints();
		gbc_lblcm.insets = new Insets(0, 0, 5, 5);
		gbc_lblcm.gridx = 0;
		gbc_lblcm.gridy = 11;
		frame.getContentPane().add(lblcm, gbc_lblcm);
		// 土壤水渗透上限值
		textField = new TipsTextField("cm");
		textField.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_textField1 = new GridBagConstraints();
		gbc_textField1.anchor = GridBagConstraints.WEST;
		gbc_textField1.insets = new Insets(0, 0, 5, 5);
		gbc_textField1.gridx = 1;
		gbc_textField1.gridy = 11;
		frame.getContentPane().add(textField, gbc_textField1);
		textField.setColumns(10);
		//textField.setToolTipText("cm");
		// 土壤水渗透下限标签
		JLabel lblNewLabel_2 = new JLabel(
				"\u571F\u58E4\u6C34\u5206\u6E17\u900F\u4E0B\u9650\uFF1A(cm)");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
		gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_2.gridx = 0;
		gbc_lblNewLabel_2.gridy = 12;
		frame.getContentPane().add(lblNewLabel_2, gbc_lblNewLabel_2);
		// 土壤水渗透下限值
		textField_10 = new TipsTextField("cm");
		textField_10.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_textField_10 = new GridBagConstraints();
		gbc_textField_10.anchor = GridBagConstraints.WEST;
		gbc_textField_10.insets = new Insets(0, 0, 5, 5);
		gbc_textField_10.gridx = 1;
		gbc_textField_10.gridy = 12;
		frame.getContentPane().add(textField_10, gbc_textField_10);
		textField_10.setColumns(10);
		//textField_10.setToolTipText("cm");
		// 土壤盐分胁迫函数形参X标签
		JLabel lblx = new JLabel(
				"\u571F\u58E4\u76D0\u5206\u80C1\u8FEB\u51FD\u6570\u5F62\u53C2X\uFF1A");
		lblx.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_lblx = new GridBagConstraints();
		gbc_lblx.insets = new Insets(0, 0, 5, 5);
		gbc_lblx.gridx = 0;
		gbc_lblx.gridy = 13;
		frame.getContentPane().add(lblx, gbc_lblx);
		// 土壤盐分胁迫函数形参X值
		textField_11 = new TipsTextField("输入文本");
		textField_11.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_textField_11 = new GridBagConstraints();
		gbc_textField_11.anchor = GridBagConstraints.WEST;
		gbc_textField_11.insets = new Insets(0, 0, 5, 5);
		gbc_textField_11.gridx = 1;
		gbc_textField_11.gridy = 13;
		frame.getContentPane().add(textField_11, gbc_textField_11);
		textField_11.setColumns(10);
		//textField_11.setToolTipText("输入文本");

		JButton button_2 = new JButton("重置");
		button_2.setFont(new Font("宋体", Font.PLAIN, 12));
		button_2.setBackground(SystemColor.text);
		button_2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				textField_0.setText(""); // 萎焉点基质势值
				textField_1.setText("");// 种植日期值
				textField_2.setText("");// 最适土壤水基质势上限值
				textField_3.setText("");// 最适土壤水基质势下限值
				textField_4.setText("");// 土壤水分胁迫函数形参值
				textField_5.setText("");// 最大扎根深度a值
				textField_6.setText("");// 最大扎根深度b值
				textField_7.setText("");// 最大扎根深度c值
				
				textField.setText("");// 土壤水渗透上限值
				textField_10.setText("");// 土壤水渗透下限值
				textField_11.setText("");// 土壤盐分胁迫函数形参X值

			}

		});
		
				// crop.setSoilWxp_Y(textField_4.getText());
				// 确定按钮
				JButton button_1 = new JButton("\u63D0\u4EA4");
				button_1.setBackground(SystemColor.text);
				button_1.setFont(new Font("宋体", Font.PLAIN, 12));
				button_1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						Connection conn = null;
						try {
							conn = MyDAO.getConnection();
						} catch (Exception e1) {
							e1.printStackTrace();
						}
						// 插入作物
						for (int i = 0; i < crop_kind.size(); i++) {
							if (i == 0 || crop_kind.get(i) != null) {
								if (defaultComboBoxModel.getSelectedItem() == crop_kind
										.get(i)) {
									flag = 0;
									break;
								} else {
									flag = 1;
								}
							}
						}
						if (flag == 1) {
							String sql1 = "insert into crop_kind (name) values('"
									+ defaultComboBoxModel.getSelectedItem() + "');";
							try {
								java.sql.PreparedStatement ptmt = conn
										.prepareStatement(sql1);
								ptmt.execute();
							} catch (SQLException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
						crop.setId(cropkind.getId((String) defaultComboBoxModel
								.getSelectedItem()));
						String[] time =textField_1.getText().split("-");
						crop.setDate(time[0] + "-"+ time[1] + "-" + time[2]);
						crop.setName((String) defaultComboBoxModel.getSelectedItem());
						crop.setWilt_jzs(textField_0.getText());
						crop.setSoilWjzs_up(textField_2.getText());
						crop.setSoilWjzs_low(textField_3.getText());
						crop.setSoilWxp_Y(textField_4.getText());
						crop.setSoilWsts_up(textField.getText());
						crop.setSoilWsts_low(textField_10.getText());
						crop.setSoilWxp_X(textField_11.getText());
						Calendar c = Calendar.getInstance();

						// System.out.println(c.get(Calendar.YEAR)+""+c.get(Calendar.MONTH)+""+c.get(Calendar.DATE));
						// 计算天数
						int year = Integer.parseInt(time[0]);
						int days = 0;
						for (int i = Integer.parseInt(time[1]); i <= 12; i++) {
							if (year == c.get(Calendar.YEAR)
									&& i == c.get(Calendar.MONTH) + 1) {
								days += (c.get(Calendar.DATE) - Integer
										.parseInt(time[2]));

								break;
							} else {

								if (i != 2) {
									if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8
											|| i == 10 || i == 12) {
										days += 31;
									} else {
										days += 30;
									}
								} else {
									if (year % 4 == 0 && year % 100 != 0
											|| year % 400 == 0) {
										days += 29;
									} else {
										days += 28;
									}
								}
							}
							if (i == 12) {
								i = 1;
								year++;
							}
						}
						crop.setMaxRootDepth(Integer.parseInt(textField_5.getText())
								+ Integer.parseInt(textField_6.getText()) * days
								+ Integer.parseInt(textField_7.getText()) + "");

						String sql2 = "insert into tra_crop_para3  values('"
								+ crop.getId() + "','" + crop.getDate() + "','"
								+ crop.getName() + "','" + crop.getCtrlzone_name()
								+ "','" + crop.getMaxRootDepth() + "','"
								+ crop.getWilt_jzs() + "','" + crop.getSoilWjzs_up()
								+ "','" + crop.getSoilWjzs_low() + "','"
								+ crop.getSoilWxp_Y() + "','" + crop.getSoilWsts_up()
								+ "','" + crop.getSoilWsts_low() + "','"
								+ crop.getSoilWxp_X() + "');";
						try {
							java.sql.PreparedStatement ptmt = conn
									.prepareStatement(sql2);
							ptmt.execute();
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						JLabel l = new JLabel("提交成功");
						l.setFont(new Font("宋体", Font.PLAIN, 12));
						JOptionPane.showMessageDialog(null, l);
						
					}
				});
				rs.close();
				stmt.close();
				conn.close();
				
						GridBagConstraints gbc_button = new GridBagConstraints();
						gbc_button.anchor = GridBagConstraints.EAST;
						gbc_button.insets = new Insets(0, 0, 0, 5);
						gbc_button.gridx = 2;
						gbc_button.gridy = 14;
						frame.getContentPane().add(button_1, gbc_button);
		GridBagConstraints gbc_button_1 = new GridBagConstraints();
		gbc_button_1.insets = new Insets(0, 0, 0, 5);
		gbc_button_1.gridx = 3;
		gbc_button_1.gridy = 14;
		frame.getContentPane().add(button_2, gbc_button_1);

		frame.setVisible(true);
		frame.pack();
		frame.setBackground(Color.WHITE);
		frame.setLocationRelativeTo(null);
	}

}
